package Xmlcompare;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;


import javax.xml.parsers.DocumentBuilderFactory;


import org.w3c.dom.Document;


public class Utils
{ 
 public static String readStringFromFile(File file)
 {
  StringBuilder ds_text = new StringBuilder();
  String str_sep = System.getProperty("line.separator");
  try
  {
   Scanner ds_scan = new Scanner(new FileInputStream(file), "UTF-8");
   while (ds_scan.hasNextLine())
    ds_text.append(ds_scan.nextLine() + str_sep);
   ds_scan.close();
  }
  catch (Exception e) 
  {
   System.err.println(file.getPath() + " :: Not read");
  }
  
  return ds_text.toString();
 }
 
 public static Document stringToDocument(String str_doc)
 {
  Document ds_doc = null;
  try
  {
   ds_doc = DocumentBuilderFactory
     .newInstance()
     .newDocumentBuilder()
     .parse(new ByteArrayInputStream(str_doc.getBytes("UTF-8")));
  }
  catch (Exception e) 
  {
	 
   System.err.println("String could not be converted to Document");
  }
  
  return ds_doc;
 }
}